//
//  SKUDefultScrPublicNewV.m
//  ZITHER
//
//  Created by weixin on 2018/9/2.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "SKUDefultScrPublicNewV.h"
#import "SKUDetailReceiveVC.h"
//#import "SKUDetailNewVc.h"

@implementation SKUDefultScrPublicNewV

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self defaultConfiguration] ;
        [self setUI];
        [self setMasonry];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
        [[tap rac_gestureSignal] subscribeNext:^(id x) {
            NSLog(@"跳转公开货源");
            
            SKUDetailReceiveVC *vc = [[SKUDetailReceiveVC alloc]init];
            vc.goodsid = self.model.goodsId;
            vc.IsEnquiry = ![self.model.myEnquiryFlag isEqualToString:@"1"];
            
            [vc setBlockRefreshData:^{
//                SKUDetailNewVc *vc = (SKUDetailNewVc*)[self getViewController:[SKUDetailNewVc class]];
//                [vc setLoad];
            }];
            
            vc.str = @"公开的货源";
            [self.getNav pushViewController:vc animated:YES];
        }];
        
        [self addGestureRecognizer:tap];
    }
    return self;
}

-(void)defaultConfiguration
{
    
}

-(void)setUI
{
    [self addSubview:self.viewBorderlines];
    [self addSubview:self.labtitle];
    [self addSubview:self.labSubtitle];
    [self addSubview:self.viewImageS];
}

-(void)setMasonry
{
    QMUIButton * btn = [[QMUIButton alloc]initWithFrame:CGRectMake(self.frame.size.width-60, 15,50, 50)];
    [btn setImage:[UIImage imageNamed:@"sku_btn_into"] forState:UIControlStateNormal];
    btn.userInteractionEnabled = YES;
    [self addSubview:btn];
    
    [self.labtitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).offset(28);
        make.top.mas_equalTo(self).offset(50);
        make.height.mas_equalTo(25);
        make.width.mas_equalTo(200);
    }];
    
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.labtitle.mas_top).offset(0);
        make.right.mas_equalTo(self).offset(-28);
        make.width.height.mas_equalTo(30);
    }];

    [self.labSubtitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.labtitle.mas_bottom).offset(10);
        make.left.mas_equalTo(self).offset(28);
        make.right.mas_equalTo(self).offset(-28);
    }];

    [self.viewImageS mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.labSubtitle.mas_bottom).offset(8);
        make.left.mas_equalTo(self).offset(28);
        make.height.mas_equalTo(60);
        make.width.mas_equalTo(kScreenW-56);
    }];
    [self.viewBorderlines mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.labtitle).offset(-14);
        make.left.mas_equalTo(self).offset(14);
        make.right.mas_equalTo(self).offset(-14);
        make.bottom.mas_equalTo(self.viewImageS).offset(14);
    }];

    [self.viewBorderlines mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.labtitle).offset(-14);
        make.left.mas_equalTo(self).offset(14);
        make.right.mas_equalTo(self).offset(-14);
        make.bottom.mas_equalTo(self.viewImageS).offset(14);
    }];

}

-(void)setModel:(skuDetailModel *)model
{
    _model = model;
    
    
    NSString *str1 = [NSString stringWithFormat:@"%@个更多公开货源",model.openSourceCount];
    self.labtitle.text = str1;
    self.labSubtitle.text = model.sourceDesc;


    if (model.fileList.count>0) {
        [self.viewImageS.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        UIScrollView *scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, kScreenW-56,60)];
        scrollview.bounces = NO;
        scrollview.showsHorizontalScrollIndicator = NO;
        scrollview.bounces = NO; // 默认为YES 取消设置NO
        // 当bounces属性为NO时，以下两个属性设置无效
        scrollview.alwaysBounceHorizontal = YES; // 水平方向弹簧效果
        scrollview.alwaysBounceVertical = YES; // 垂直方向弹簧效果
        scrollview.decelerationRate = 0.1; // 值域 0~1 值越小减速停止的时间越短
        scrollview.backgroundColor = [UIColor whiteColor];
        [self.viewImageS addSubview:scrollview];
        scrollview.contentSize = CGSizeMake(68*model.fileList.count+15,0);
        
        for (int j = 0; j<model.fileList.count; j++) {
            UIImageView * imageV = [[UIImageView alloc]initWithFrame:CGRectMake(j*68+5,0, 60,60)];
            [imageV setCornerRadiusWithRadius:5 isMasks:YES];
            imageV.backgroundColor = [UIColor whiteColor];
            imageV.contentMode = UIViewContentModeScaleAspectFill;
            
            NSString *str = [NSString stringWithFormat:@"%@%@",RootUrlImage,model.fileList[j]];
            
            [imageV sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"watchSmale"]];
            
            [scrollview addSubview:imageV];
        }
    }
}

-(QMUILabel *)labtitle{
    if (!_labtitle) {
        _labtitle = [[QMUILabel alloc]initWithFrame:CGRectMake(15,15 , 200, 20)];
        _labtitle.font = [UIFont systemFontOfSize:18];
//        _labtitle.text = @"31个更多的公开资源";
    }
    return _labtitle;
}

-(QMUILabel *)labSubtitle{
    if (!_labSubtitle) {
        _labSubtitle = [[QMUILabel alloc]initWithFrame:CGRectMake(20,70, kScreenW-65, 15)];
        _labSubtitle.font = [UIFont systemFontOfSize:12];
//        _labSubtitle.text = @"31个更多的公开资源31个更多的公开资源31个更多的公开资源31个更多的公开资源31个更多的公开资源31个更多的公开资源31个更多的公开资源31个更多的公开资源31个更多的公开资源";

        _labSubtitle.numberOfLines = 0;
    }
    return _labSubtitle;
}
-(UIView *)viewBorderlines{
    if (!_viewBorderlines) {
        _viewBorderlines = [[UIView alloc]initWithFrame:CGRectMake(0,0, kScreenW-58, 300)];
        [_viewBorderlines setCornerRadiusWithRadius:10 isMasks:YES];
        [_viewBorderlines setBorderWithColor:[UIColor RGBColorWithR:224 g:224 b:224] width:1.5];
    }
    return _viewBorderlines;
}
-(UIView *)viewImageS{
    if (!_viewImageS) {
        _viewImageS = [[UIView alloc]initWithFrame:CGRectMake(14,70, kScreenW-65, 15)];
    }
    return _viewImageS;
}



@end
